import React, { useEffect } from "react";
import { Form, Input } from "antd";

import { prompt } from "@/service";
import type { WrappedComponentProps } from '@yaf/pro-ui';


interface InitAdminProps extends WrappedComponentProps {
    accountId: string;
}

const InitAdmin: React.FC<InitAdminProps> = (props) => {
    const { form } = useInitAdmin(props);

    return <Form
        form={form}
        labelCol={{ span: 5 }}
        wrapperCol={{ span: 15 }}
    >
        <Form.Item label="用户名" name="userName">
            <Input />
        </Form.Item>
    </Form>
}

export default InitAdmin;

const useInitAdmin = (props: InitAdminProps) => {
    const { modalControl } = props;
    const [form] = Form.useForm();

    useEffect(() => {
        modalControl.registerOk(handleSubmit)
    })

    const handleSubmit = () => {
        form.validateFields().then(() => {
            prompt.success("操作成功!");
            modalControl.close();
        }).catch(() => modalControl.hideSaving());
    }

    return { form }
}
